import { ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { ApiService } from '@core/services/api';
import { HttpClient } from '@angular/common/http';
import { NzMessageService, NzModalRef } from 'ng-zorro-antd';
import { UtilService } from '@core/services/util.service';

@Component({
  selector: 'app-cost-edit',
  templateUrl: './cost-edit.component.html',
  styles: []
})
export class CostEditComponent implements OnInit {
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  @Input()type: 0 | 1;
  @Input()id:string
  @Input()
  set _param(value) {
    if (!value) return;
    this.param = value;
    console.log(this.param);
    
  };
  param: any;
  value:any;
  nodes=[];
  timeout:any="";
  show:boolean=true;
  showForm = false;
  isLoading:boolean=false;
  schema: SFSchema = {
    properties: {
      itemName: {
        type: 'string',
        title: '名称',
      },
      openType:{
        type:"string",
        title:"类型",
        enum:[
          {label:"小区开通二维码",value:"1"},
          {label:"个人开通二维码",value:"2"}
        ],
        ui:{
          widget:'select'
        }
      },
      monthlyRent: {
        type: 'number',
        title: '费用(元)',
      }
    },
    required: ['itemName','openType', 'monthlyRent']
  }

  formSubmit(data) {
    let url = '';
    if(this.type == 0){
      url = "/core/qr/pay/save"
    }else if(this.type == 1){
      url = "/core/qr/manager/update"
    }
    const body = {...data}
    body.itemType = 3
    body.areaId = this.id
    body.monthlyRent = body.monthlyRent * 100
    this.http.request<any>("post", url, {body}).subscribe(res => {
      console.log(res)
      if (res.status === '200' || res.status === '201') {
        this.msg.success('操作成功');
        this.modalRef.triggerOk();
      } else {
        this.msg.error(res.message)
      }
    })

  }

  constructor(
    private api: ApiService,
    private http: HttpClient,
    private msg: NzMessageService,
    private modalRef: NzModalRef,
    private util: UtilService,
    private ref: ChangeDetectorRef,
  ) { }

  async ngOnInit() {
    
  }


}
